package com.testing.xl;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFRow;


public class Read_XL {

	//Main Method 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Map<String,String> A1=new HashMap<String,String>();
		List<String> list = new ArrayList<String>();
		try
        {
            FileInputStream file = new FileInputStream(new File("c:\\Excel\\Test.xls"));
            //Create Workbook instance holding reference to .xlsx file
            HSSFWorkbook workbook = new HSSFWorkbook(file);
            //Get first/desired sheet from the workbook
            HSSFSheet sheet = workbook.getSheetAt(0);
            //Iterate through each rows one by one
            
            Iterator<Row> rowIterator = sheet.iterator();
            while (rowIterator.hasNext())
            {
                Row row = rowIterator.next();
                //For each row, iterate through all the columns
                Iterator<Cell> cellIterator = row.cellIterator();
                 
                String username = "";
                String password = "";
                int i = 0;
                
                while (cellIterator.hasNext())
                {
                    Cell cell = cellIterator.next();
                   System.out.println(cell.getStringCellValue());
             	
                   if(i == 0){
                	   username =cell.getStringCellValue(); 
                   }else{
                	   password = cell.getStringCellValue(); 
                   }
                   
                   i = i+1;
                }
                //System.out.println("");
                
               A1.put(username, password);
                
            }
            
            Read_XL re = new Read_XL();
            
            for(String username : A1.keySet()){
            	
            	re.display(username, A1.get(username));
            	
            }
            
            
            file.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

	
	public void display(String username, String password){
	
		System.out.println("Username : "+username+":"+password);
		
	}

	}



